from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2023-01-11 14:02:53.985902
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Wed, 11, Jan, 2023
Time: 14:03:01
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -51.3726
Nobs: 898.000 HQIC: -51.6699
Log likelihood: 11904.5 FPE: 3.02151e-23
AIC: -51.8537 Det(Omega_mle): 2.73488e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.295994 0.048745 6.072 0.000
L1.Burgenland 0.108356 0.033759 3.210 0.001
L1.Kärnten -0.105519 0.018113 -5.826 0.000
L1.Niederösterreich 0.216360 0.070755 3.058 0.002
L1.Oberösterreich 0.076616 0.066858 1.146 0.252
L1.Salzburg 0.249694 0.035848 6.965 0.000
L1.Steiermark 0.032010 0.047069 0.680 0.496
L1.Tirol 0.123280 0.038130 3.233 0.001
L1.Vorarlberg -0.059727 0.032864 -1.817 0.069
L1.Wien 0.066713 0.059656 1.118 0.263
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.059411 0.099582 0.597 0.551
L1.Burgenland -0.007305 0.068968 -0.106 0.916
L1.Kärnten 0.048404 0.037003 1.308 0.191
L1.Niederösterreich -0.166469 0.144546 -1.152 0.249
L1.Oberösterreich 0.354824 0.136586 2.598 0.009
L1.Salzburg 0.285898 0.073235 3.904 0.000
L1.Steiermark 0.107557 0.096158 1.119 0.263
L1.Tirol 0.321240 0.077896 4.124 0.000
L1.Vorarlberg 0.024985 0.067139 0.372 0.710
L1.Wien -0.022922 0.121873 -0.188 0.851
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.202251 0.025517 7.926 0.000
L1.Burgenland 0.092523 0.017673 5.235 0.000
L1.Kärnten -0.008634 0.009482 -0.911 0.362
L1.Niederösterreich 0.267607 0.037039 7.225 0.000
L1.Oberösterreich 0.106675 0.034999 3.048 0.002
L1.Salzburg 0.054189 0.018766 2.888 0.004
L1.Steiermark 0.016797 0.024640 0.682 0.495
L1.Tirol 0.099545 0.019960 4.987 0.000
L1.Vorarlberg 0.057468 0.017204 3.340 0.001
L1.Wien 0.112353 0.031229 3.598 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.106865 0.026122 4.091 0.000
L1.Burgenland 0.050340 0.018091 2.783 0.005
L1.Kärnten -0.015854 0.009706 -1.633 0.102
L1.Niederösterreich 0.199782 0.037917 5.269 0.000
L1.Oberösterreich 0.271300 0.035829 7.572 0.000
L1.Salzburg 0.117753 0.019211 6.130 0.000
L1.Steiermark 0.101521 0.025224 4.025 0.000
L1.Tirol 0.122973 0.020433 6.018 0.000
L1.Vorarlberg 0.070013 0.017612 3.975 0.000
L1.Wien -0.025609 0.031969 -0.801 0.423
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.139509 0.046762 2.983 0.003
L1.Burgenland -0.052523 0.032386 -1.622 0.105
L1.Kärnten -0.035195 0.017376 -2.025 0.043
L1.Niederösterreich 0.164694 0.067877 2.426 0.015
L1.Oberösterreich 0.127317 0.064139 1.985 0.047
L1.Salzburg 0.291132 0.034390 8.466 0.000
L1.Steiermark 0.034956 0.045155 0.774 0.439
L1.Tirol 0.156877 0.036579 4.289 0.000
L1.Vorarlberg 0.107727 0.031527 3.417 0.001
L1.Wien 0.067132 0.057230 1.173 0.241
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.066752 0.037225 1.793 0.073
L1.Burgenland 0.039479 0.025781 1.531 0.126
L1.Kärnten 0.049524 0.013832 3.580 0.000
L1.Niederösterreich 0.224640 0.054033 4.157 0.000
L1.Oberösterreich 0.261965 0.051057 5.131 0.000
L1.Salzburg 0.061597 0.027376 2.250 0.024
L1.Steiermark -0.005651 0.035945 -0.157 0.875
L1.Tirol 0.158043 0.029118 5.428 0.000
L1.Vorarlberg 0.067942 0.025097 2.707 0.007
L1.Wien 0.076369 0.045557 1.676 0.094
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.198377 0.044970 4.411 0.000
L1.Burgenland 0.018388 0.031145 0.590 0.555
L1.Kärnten -0.056613 0.016710 -3.388 0.001
L1.Niederösterreich -0.098560 0.065275 -1.510 0.131
L1.Oberösterreich 0.174938 0.061681 2.836 0.005
L1.Salzburg 0.062446 0.033072 1.888 0.059
L1.Steiermark 0.224597 0.043424 5.172 0.000
L1.Tirol 0.476594 0.035177 13.548 0.000
L1.Vorarlberg 0.051120 0.030319 1.686 0.092
L1.Wien -0.049514 0.055037 -0.900 0.368
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.148424 0.050397 2.945 0.003
L1.Burgenland 0.000897 0.034903 0.026 0.979
L1.Kärnten 0.067490 0.018726 3.604 0.000
L1.Niederösterreich 0.204087 0.073152 2.790 0.005
L1.Oberösterreich -0.070785 0.069124 -1.024 0.306
L1.Salzburg 0.220313 0.037063 5.944 0.000
L1.Steiermark 0.108738 0.048664 2.234 0.025
L1.Tirol 0.081108 0.039422 2.057 0.040
L1.Vorarlberg 0.128907 0.033978 3.794 0.000
L1.Wien 0.111776 0.061678 1.812 0.070
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.357826 0.030026 11.917 0.000
L1.Burgenland 0.010752 0.020795 0.517 0.605
L1.Kärnten -0.025157 0.011157 -2.255 0.024
L1.Niederösterreich 0.230233 0.043584 5.283 0.000
L1.Oberösterreich 0.144030 0.041184 3.497 0.000
L1.Salzburg 0.053763 0.022082 2.435 0.015
L1.Steiermark -0.015334 0.028994 -0.529 0.597
L1.Tirol 0.120290 0.023487 5.122 0.000
L1.Vorarlberg 0.072842 0.020244 3.598 0.000
L1.Wien 0.052021 0.036747 1.416 0.157
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.040807 0.175026 0.191062 0.176051 0.153463 0.137633 0.071812 0.228458
Kärnten 0.040807 1.000000 0.006081 0.134309 0.028051 0.100503 0.426937 -0.047163 0.103900
Niederösterreich 0.175026 0.006081 1.000000 0.361257 0.180577 0.328094 0.148847 0.199726 0.353790
Oberösterreich 0.191062 0.134309 0.361257 1.000000 0.244221 0.351720 0.197609 0.185237 0.285042
Salzburg 0.176051 0.028051 0.180577 0.244221 1.000000 0.162099 0.150497 0.155173 0.148872
Steiermark 0.153463 0.100503 0.328094 0.351720 0.162099 1.000000 0.174234 0.154001 0.108806
Tirol 0.137633 0.426937 0.148847 0.197609 0.150497 0.174234 1.000000 0.130180 0.175804
Vorarlberg 0.071812 -0.047163 0.199726 0.185237 0.155173 0.154001 0.130180 1.000000 0.027628
Wien 0.228458 0.103900 0.353790 0.285042 0.148872 0.108806 0.175804 0.027628 1.000000